package presentacion;

import integracion.DatabaseManager;
import integracion.TareaDAO;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import share.Tarea;

public class IngresarTarea extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
{
static final long serialVersionUID = 1L;


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
	doAll(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
	doAll(request, response);
}

private void doAll(HttpServletRequest request, HttpServletResponse response) throws IOException
{

	if(request.getParameter("accion").equals("Aceptar"))
	{
		Tarea tarea = new Tarea();
		tarea.setDuracion(Integer.parseInt(request.getParameter("duracion")));
		tarea.setNombre(request.getParameter("nombre"));
		tarea.setBitacora(request.getParameter("bitacora"));
		tarea.setFecha_Inicio(request.getParameter("Finicial"));
		tarea.setFecha_Final(request.getParameter("Ffinal"));

		try
		{
			TareaDAO dao = new TareaDAO(DatabaseManager.getConnection());
			dao.insert(tarea);

		} catch (SQLException e)
		{
			e.printStackTrace();
		}
	}

	response.sendRedirect("index.jsp?page=GestionarTareas/GestionarTareas");
}
}
